#ifndef __THREAD_HPP__
#define __THREAD_HPP__

#include<iostream>
#include<string>
#include<unistd.h>
#include<functional>
#include<pthread.h>

namespace ThreadModule
{
    template<typename T>
    using func_t = std::function<void(T&)>;

    template<class T>
    class Thread
    {
        public:
        void Excute()
        {
            _func(_data);
        }
        public:
        Thread(func_t<T> func, T &data, const std::string &name="none-name")
        :_func(func),_data(data),_threadname(name),_stop(stop)
        {
        }
        static void *threadroutine(void *args) // 类成员函数，形参是有this指针的！！
        {
            Thread<T> *self = static_cast<Thread<T> *>(args);
            self->Excute();
            return nullptr;
        }
        private:
        pthread_t _tid;
        std::string _threadname;
        T &_data;
        func_t <T> _func;
        bool _stop;
    };
}

#endif